package com.byq.mm.common.engine.listener;


import com.byq.mm.common.engine.Environment;

import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.roster.Roster;

public class PresenceListener extends AbstractListener implements org.jivesoftware.smack.StanzaListener {

		public PresenceListener(Environment e) {
			super(e);
			
		}
	@Override
	public void processPacket(Stanza s) {
		Presence p = (Presence)s;
		if(p.getType() == Presence.Type.unsubscribe){

			Roster.getInstanceFor(env.getConnection()).getEntry(p.getFrom());
		}
		if(p.getType() == Presence.Type.subscribe){
			String from = p.getFrom().toString();
			//env.getConnection().getRoster().getEntry(from);
			env.getEventCenter().notifyAddContactRequest(from);
		}
	}

}
